package com.smartens.boit.adapter;

import android.annotation.SuppressLint;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.smartens.boit.R;
import com.smartens.boit.activity.viewmodel.MainActivityViewMode;
import com.smartens.boit.bean.ControlBean;
import com.smartens.boit.bean.FaultBean;
import com.smartens.boit.bean.ProcessedBean;

import org.w3c.dom.Text;

import java.util.ArrayList;
import java.util.List;

import static android.content.ContentValues.TAG;

/**
 * @Description 已处理报警适配器
 * @Author xdz
 * @Date 2021/3/4
 */

public class ProcessedAdapter extends RecyclerView.Adapter<ProcessedAdapter.ViewHolder> {
    private List<ProcessedBean> mList;
    private OnItemClickListener onItemClickListener;

    public ProcessedAdapter(List<ProcessedBean> list) {
        mList = list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        //将我们自定义的item布局R.layout.item_one转换为View
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_latest, parent, false);
        //将view传递给我们自定义的ViewHolder
        ViewHolder holder = new ViewHolder(view);
        //返回这个MyHolder实体
        return holder;
    }

    /**
     * 通过方法提供的ViewHolder，将数据绑定到ViewHolder中
     *
     * @param holder
     * @param position
     */
    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        //    Log.v("adapter", "onBindViewHolder: 111"+position );
        holder.name.setText(mList.get(position).getDeviceName());
        holder.number.setText("设备编号 " + mList.get(position).getDeviceNum());
        holder.date.setText(mList.get(position).getFaultTime());
        holder.tip.setText("查看详情");
        holder.latest.setVisibility(View.INVISIBLE);
        holder.linearLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClick(v, holder.getAdapterPosition());
                }
            }
        });
    }

    /**
     * 获取数据源总的条数
     *
     * @return
     */
    @Override
    public int getItemCount() {
        return mList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout linearLayout;
        TextView name;
        TextView number;
        TextView date;
        TextView latest;
        TextView deal;
        TextView tip;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            linearLayout = itemView.findViewById(R.id.lin);
            name = itemView.findViewById(R.id.name);
            number = itemView.findViewById(R.id.number);
            date = itemView.findViewById(R.id.time);
            latest = itemView.findViewById(R.id.tv_latest);
            deal = itemView.findViewById(R.id.tv_deal);
            tip = itemView.findViewById(R.id.tip);
        }
    }

    /**
     * 供外部调用设置监听
     *
     * @param onItemClickListener
     */
    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }


    /**
     * 自定义的接口
     */
    public interface OnItemClickListener {
        void onItemClick(View view, int position);
    }

    public void setData(List<ProcessedBean> data) {
        mList = data;

    }
}
